package com.unitd.frame.mybatis.core.entity;

import com.unitd.frame.comm.utils.PropertiesUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;

/**
 * @desc 系统中与数据库映射的实体类的公共基类, 用于序列化
 * @filename BaseEntity.java
 * @copyright www.unitd.com
 * @author Hudan
 * @version 1.0
 * @date 2016/12/20
 */
public abstract class BaseEntity implements Serializable, Cloneable {

	/** 删除标记（0:正常;1:删除） */
	public static final String DEL_FLAG_NORMAL = "0";
	public static final String DEL_FLAG_DELETE = "1";
	/** 此处参数需要注意,如果数据库类型进行了更改,需要更改此参数的值.目前在这里写死,以后改成从数据库中读取 */
	protected static final String dbName = PropertiesUtils.get("db.type", "mysql");

	/**
	 * @desc 获取主键ID
	 * @return Serializable
	 */
	public abstract Serializable getId();

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}

	@Override
	public boolean equals(Object o) {
		return EqualsBuilder.reflectionEquals(this, o);
	}

	@Override
	public int hashCode
			() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public Object clone
			() throws CloneNotSupportedException {
		return super.clone();
	}
}